#include "Troll.hh"

Troll::Troll()
    : Character("Jernsvelgeren-the Iron-Devouring Troll", 
        "In the 18th-century Norwegian fjords, a Viking blacksmith who defied mountain gods was sacrificed by his clan. Bound to a lichen-covered altar with iron chains, his eyes devoured by ravens, his decaying body was cast into boiling tar mixed with iron filings. When the aurora burned crimson, his wrath awoke glacial corpse-mites—swarms of metallic beetles gnawed through bedrock to rebuild him: molten bronze for organs, frozen moss for veins, and cursed runes smoldering beneath iron flesh. Since then, the cliffs echo nightly with phantom hammering, as fishermen whisper of Jernsvelgeren—the Iron-Devouring Troll."
        "Troll manifests as a 5-meter tar-behemoth oozing corrosive sludge, exposing writhing insectoid gears beneath. Severed limbs regenerate via lichen tendrils, while its core—a cursed Viking forge—burns with three bronze skulls belching sulfur. When enraged, its runic tattoos project blood-red glyphs to immobilize prey, forcing them to drink molten iron. Victims slowly petrify into shrieking statues studded with jagged metal thorns, eternally embedded in Troll's lair as macabre pillars.", 
        300, 30, 25) ,dodgeProbability(0.3){}

Troll::~Troll() {}

Troll::Troll(const Troll& other) : Character(other), dodgeProbability(other.dodgeProbability) {
    // Copy constructor logic if needed
}
Troll& Troll::operator=(const Troll& other) {
    if (this != &other) {
        Character::operator=(other); // Call the assignment operator of the base class
        dodgeProbability = other.dodgeProbability;
    }
    return *this;
}
bool Troll::takeDamage(unsigned damage){
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_real_distribution<> dis(0.0, 1.0);

    float randNum = dis(gen);
    if (randNum < dodgeProbability) {
    damage = 0;
    }
    if (damage > getDefense() && damage < getHealth()) {
        addHealth(-(damage - getDefense()));
    }
    else if (damage > getDefense() && damage >= getHealth()) {
        setHealth(0);
    }
    return isAlive();
}